<template>
  <!-- 用户的提现流水页面添加修改页面 -->
  <el-dialog :visible.sync="visible" :title="!dataForm.id ? '新增提现' : '打款金额'" :close-on-click-modal="false"
             :close-on-press-escape="false">
    <el-form :model="dataForm" :rules="dataRule" ref="dataForm" @keyup.enter.native="dataFormSubmitHandle()" label-width="120px">
      <el-form-item prop="applyAmount" label="提现金额">
        <div style="color: #bd2323;font-weight: 800;font-size: 25px;">￥{{formatNumber(dataForm.applyAmount)}}</div>
      </el-form-item>
      <el-form-item prop="rate" label="手续费">
        <div>￥{{formatNumber(dataForm.rate)}}</div>
      </el-form-item>
      <el-form-item prop="actualAmount" label="需付费用">
        <div style="color: #bd2323;font-weight: 800;font-size: 25px;">￥{{formatNumber(dataForm.actualAmount)}}</div>
      </el-form-item>
      <el-form-item prop="payStatus" label="打款状态">
        <ren-select v-model="dataForm.payStatus" dict-type="pay_status" placeholder="请选择打款状态"></ren-select>
      </el-form-item>
      <el-form-item prop="proof" label="付款凭证">
        <el-input v-model="dataForm.proof" placeholder="请输入付款凭证号" clearable></el-input>
      </el-form-item>
    </el-form>
    <template slot="footer">
      <el-button @click="visible = false">取消</el-button>
      <el-button type="primary" @click="dataFormSubmitHandle()">确认</el-button>
    </template>
  </el-dialog>
</template>

<script>
import debounce from 'lodash/debounce'
import {formatNumber} from "../../../utils";

export default {
  data() {
    return {
      visible: false,
      dataForm: {
        id: '',                         //id
        actualAmount:'',                //实际金额
        applyAmount: '',                //提现金额
        applyRemark: '',                //提现备注
        bankBranch: '',                 //支行名称
        bankName: '',                   //银行名称
        bankNumber: '',                 //银行卡号
        bankUsername: '',               //收款人姓名
        createDate: '',                 //创建时间
        createDateStart: '',            //开始创建时间
        createDateEnd: '',              //结束创建时间
        payStatus: '',                  //待支付;已支付
        proof: '',                      //付款凭证
        rate: '',                       //提现手续费
        userId: '',                     //用户编号
      }
    }
  },
  computed: {
    dataRule() {
      return {
        payStatus: [
          {required: true, message: this.$t('validate.required'), trigger: 'blur'}
        ],
      }
    }
  },
  methods: {
    formatNumber,
    init() {
      this.visible = true
      this.$nextTick(() => {
        this.$refs['dataForm'].resetFields()
        if (this.dataForm.id) {
          this.getInfo()
        }
      })
    },
    // 获取信息
    getInfo() {
      this.$http.get(`/api/userCashout/${this.dataForm.id}`).then(({data: res}) => {
        if (res.code !== 0) {
          return this.$message.error(res.msg)
        }
        this.dataForm = {
          ...this.dataForm,
          ...res.data
        }
        this.dataForm.status = 1
      }).catch(() => {
      })
    },
    // 表单提交
    dataFormSubmitHandle: debounce(function () {
      this.$refs['dataForm'].validate((valid) => {
        if (!valid) {
          return false
        }
        this.$http[!this.dataForm.id ? 'post' : 'put']('/api/userCashout', this.dataForm).then(({data: res}) => {
          if (res.code !== 0) {
            return this.$message.error(res.msg)
          }
          this.$message({
            message: this.$t('prompt.success'),
            type: 'success',
            duration: 500,
            onClose: () => {
              this.visible = false
              this.$emit('refreshDataList')
            }
          })
        }).catch(() => {})
      })
    }, 1000, {'leading': true, 'trailing': false}),
  }
}
</script>
